package com.zhufeng.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.zhufeng.base.redis.ZFRedisUtil;
import com.zhufeng.web.service.MsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName: DataController
 * @Description 多数据源切换演示
 * @author 月夜烛峰
 * @date 2022/9/5 14:40
 */
@RestController
@RequestMapping("data")
public class DataController {

    //@Resource

    //@Autowired
    static MsgService msgService;

    @Autowired
    public void setDatastore(MsgService msgService) {
        DataController.msgService = msgService;
    }

    @Resource
    RedisTemplate<String, Object> redisTemplate;

    @RequestMapping("redis")
    public Object showRedis(){
        redisTemplate.opsForValue().set("zhufeng-test", "测试");
        //return redisTemplate.opsForValue().get("zhufeng-test");
        return ZFRedisUtil.get("zhufeng-test");
    }

    @RequestMapping("master")
    public JSONObject showUser(){

        return msgService.showFirstUser();
    }

    @RequestMapping("slave")
    public JSONObject showMsg(){
        return msgService.showFirstMsg();
    }
}
